﻿$.ajaxSetup({ url: "SIMList.aspx", type: "post", dataType: "json" });
var pageIndex = 0;
var pageSize = 20;
var page_count = 0;

function btnSearch_Click() {

    var inpCode = $("#txtCode").val();
    var inpTelephone = $("#txtTelephone").val();
    var inpUser = $("#txtUser").val();
    var inpBeginDate = $("#txtBeginDate").val();
    var inpEndDate = $("#txtEndDate").val();

    $.ajax({
        data: { method: "search",
            code: inpCode,
            telephone: inpTelephone,
            user: inpUser,
            beginDate: inpBeginDate,
            endDate: inpEndDate,
            page: pageIndex,
            size: pageSize
        }
        , success: function (json) {
            // 先删除原来的行，否则会多次绑定。
            $("#tbl_SIMCardList").find("tr:not(.td_title)").remove();
            // 填充表格
            $("#tbl_SIMCardList").append("#full_SIMCardList", json.SIMCardList);
            // 分页
            page_count = Math.ceil(json.RowsCount / pageSize);
            PagerInit();
        }
    });
}

function PagerInit() {
    $(document).ready(function () {
        $("#pager").pager({ pagenumber: pageIndex, pagecount: page_count, buttonClickCallback: PageClick });
    });
}
function PageClick(pageclickednumber) {
    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: page_count, buttonClickCallback: PageClick });
    pageIndex = pageclickednumber;
    btnSearch_Click();
}

function SIMRecharge(code,telephone) {
    location.replace("../SIM/SIMRecharge.aspx?code=" + code + "&telephone=" + telephone);
}

function SIMRecord(code, telephone) {
    location.replace("../SIM/SIMRecord.aspx?code=" + code + "&telephone=" + telephone);
}

function init() {
    $("#txtBeginDate").datepicker();
    $("#txtEndDate").datepicker();
    $("#btnSearch").click(function () {
        btnSearch_Click();
    });
}

